package com.sync.utils.project.gasStatistics.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.sync.utils.common.base.controller.impl.BaseControllerImpl;
import com.sync.utils.common.enums.ResultCodeEnum;
import com.sync.utils.framework.result.R;
import com.sync.utils.project.demo.pojo.UserInfo;
import com.sync.utils.project.gasStatistics.pojo.GasDayRes;
import com.sync.utils.project.gasStatistics.pojo.GasMonthReq;
import com.sync.utils.project.gasStatistics.pojo.GasMonthRes;
import com.sync.utils.project.gasStatistics.pojo.GasUserRes;
import com.sync.utils.project.gasStatistics.service.GasService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 天然气查询接口
 *
 * @Author YWF
 * @Date 2025/3/15 21:46
 */
@Slf4j
@RestController
@RequestMapping("/gas/")
public class GasController extends BaseControllerImpl {

    @Autowired
    private GasService gasService;

    @RequestMapping(value = "getRemoteGasMonthBillList", method = RequestMethod.POST)
    public R<UserInfo> getRemoteGasMonthBillList(@RequestBody GasMonthReq gasReq) {
        List<GasMonthRes> gasResList = gasService.getRemoteGasMonthBillList(gasReq);
        if (CollectionUtil.isNotEmpty(gasResList)) {
            return R.ok().data(gasResList);
        }
        return R.setResult(ResultCodeEnum.RESULT_NULL);
    }

    //@Scheduled(cron = "${job.gasMonthBillTask}")
    @RequestMapping(value = "taskGasMonthBill", method = RequestMethod.POST)
    public R taskGasMonthBill() {
        gasService.taskGasMonthBillList();
        return R.ok();
    }

    @RequestMapping(value = "getRemoteGasDayBillList/{mdmCode}/{userCode}", method = RequestMethod.POST)
    public R getGasDayBillList(@PathVariable("mdmCode") String mdmCode, @PathVariable("userCode") String userCode) {
        List<GasDayRes> gasResList = gasService.getRemoteGasDayBillList(mdmCode, userCode);
        if (CollectionUtil.isNotEmpty(gasResList)) {
            return R.ok().data(gasResList);
        }
        return R.setResult(ResultCodeEnum.RESULT_NULL);
    }

    //@Scheduled(cron = "${job.gasMonthBillTask}")
    @RequestMapping(value = "taskGasDayBill", method = RequestMethod.POST)
    public R taskGasDayBill() {
        gasService.taskGasDayBillList();
        return R.ok();
    }

    @RequestMapping(value = "getGasUserInfo/{userCode}", method = RequestMethod.GET)
    public R<GasUserRes> getGasUserInfo(@PathVariable("userCode") String userCode) {
        GasUserRes gasUserInfo = gasService.getGasUserInfo(userCode);
        if (ObjectUtils.isEmpty(gasUserInfo)) {
            return R.setResult(ResultCodeEnum.RESULT_NULL);
        }
        return R.ok().data(gasUserInfo);
    }

}
